<?php

namespace app\common\event;
use app\common\libs\InsideApi;
use think\Exception;
use yiqiniu\inside_sdk\message_libs\MessageBuilder;

/**
 * 扫码红包通知
 */
class OrderBalanceSuccessEventHandler
{
    public  function handle(array $params){

        if(empty($params['open_id']) || empty($params['money'])){
            return;
        }
        // title:活动名称,type:导购名红包/积分,money:金额,:time:扫码时间,shop_name:门店名称,balance:账户余额，remark:备注
        $paramsData = [
                'title' => '',
                'type' => '',
                'money' => '',
                'time' => '',
                'shop_name' => '',
                'balance' => '',
                'remark' => ''
        ];
        $paramsData = array_merge($paramsData,$params);

        try {
            $balance_data = MessageBuilder::getInstance()
                ->setReceivers(1, $params['open_id'])
                ->setUserType(1)
                ->setTpl('balance_change')
                ->setData($paramsData)->getData();
            InsideApi::Message()->Send($balance_data);
        }catch (Exception $e){
            writelog('请求扫码红包通知出错：' . $e->getMessage());
        }

    }
}
